package com.yc.snack.controller;

import com.yc.snack.biz.IAdminInfoBiz;
import com.yc.snack.biz.impl.AdminInfoBizImpl;
import com.yc.snack.entity.AdminInfo;
import com.yc.snack.util.ConstantInfo;
import com.yc.snack.util.RequestParamUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/*")
public class AdminInfoController extends BaseController {

    /**
     * 登录方法
     * @param request
     * @param response
     */
    protected void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 获取参数
    	//System.out.println("122344");
        AdminInfo af = RequestParamUtil.getParams(AdminInfo.class, request);
        System.out.println(af);

        // 调用业务模型层处理
        IAdminInfoBiz adminInfoBiz = new AdminInfoBizImpl();
        AdminInfo adminInfo = adminInfoBiz.login(af);

        // 返回结果
        if(adminInfo == null) {
            this.send(response, 500, "账号或密码错误");
            return;
        }

        request.getSession().setAttribute(ConstantInfo.CURRENTLOGINADMIN, adminInfo);
        this.send(response, 200, "登录成功");
        return;

    }
}
